package cn.snailhd.core.base.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 统一简单分页类
 * Title: PageVo.java
 * Description:
 * Copyright by www.rsrtech.net
 * @author huangdian 
 * @date 2018年6月11日 
 * @version 1.0  
 * @param <T>
 */
public class PageVo<T> implements Serializable {
	 
	private static final long serialVersionUID = 1L;
	
	private List<T> rows;
	private int count;
	
	/**
	 * 计算数据库分页索引
	 * @return
	 */
	
	public List<T> getRows() {
		return (null!=rows) ? rows:new ArrayList<T>();
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	/**
	 * 计算分页
	 * @param params
	 * @return
	 */
	public static boolean mathIndex(Map params){
		Object _page = params.get("page");
		Object _size = params.get("size");
		int page = 0,size=0,index=0;
		
		if(_page==null || _size==null) return false;
		
		
		if(_page instanceof Integer) page = (int) _page;
		if(_page instanceof String) page = Integer.parseInt((String)_page);
		
		
		if(_size instanceof Integer) size = (int) _size;
		if(_size instanceof String) size = Integer.parseInt((String)_size);
		
		index= (page-1) * size;
		params.put("index", index);
		
		return true;
	}
}
